//
//  Status.swift
//  WeiBo
//
//  Created by 小小罗 on 15/11/12.
//  Copyright © 2015年 RealMadrid. All rights reserved.
//

import UIKit
//微博数据模型
class Status: NSObject {

    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博创建时间
    var created_at: String?
    /// 微博来源
    var source: String?
    // 缩略图配图数组 key: thumbnail_pic
    var pic_urls: [[String: String]]?
    /// 用户模型
    var user: User?
    //被转发的原微博信息字段
    var retweeted_status: Status?

    
    init(dict: [String: AnyObject]) {
        super.init()
        
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        // 如果使用 KVC 时，value 是一个字典，会直接给属性转换成字典
        //因为user里边还是一个字典 等于说这里字典嵌套字典 所以这里应该判断如果是user的话 再次字典转模型
        if key == "user" {
        
            if let dict = value as?[String :AnyObject] {
            
                user = User(dict:dict)
            }
            
                    return
        }
        
        //判断key是否是retweeted_status
        
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject]{
            
                retweeted_status = Status(dict: dict)
            }
                return
        }
        
        
         super.setValue(value, forKey: key)
    }
    

    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        let keys = ["id", "text", "created_at", "source","user","pic_urls","retweeted_status"]
        
        return dictionaryWithValuesForKeys(keys).description
    }

    
}
